//
//  RCMyOrderListDataModel.m
//  RocketProject
//
//  Created by chen jiedan on 13-9-19.
//  Copyright (c) 2013年 Rocket. All rights reserved.
//

#import "RCMyOrderListDataModel.h"
#import "KFObjectExtension.h"

@implementation RCMyOrderItemDataModel

@synthesize shopName = _shopName;
@synthesize status   = _status;
@synthesize userName = _userName;
@synthesize mobile   = _mobile;
@synthesize dateTime = _dateTime;
@synthesize content  = _content;
@synthesize shopID    =_shopID;

- (void) dealloc
{
    KF_RELEASE_SAFELY(_shopName);
    KF_RELEASE_SAFELY(_status);
    KF_RELEASE_SAFELY(_userName)
    KF_RELEASE_SAFELY(_dateTime);
    KF_RELEASE_SAFELY(_content);
    KF_RELEASE_SAFELY(_mobile);
    KF_RELEASE_SAFELY(_shopID);
    [super dealloc];
}

@end

@implementation RCMyOrderListDataModel
// 将JSON数据解析为数据模型
-(id) parseDataFromJSON:(NSDictionary*)data
{
    // 输入参数判断
    if ( nil == data )
        return nil;
    
    // 分配数据模型对象内存
    RCMyOrderListDataModel *retObject = nil;
    retObject = [[RCMyOrderListDataModel alloc] init];
    if ( nil == retObject )
        return retObject;
    
    NSMutableArray *listItems = [[NSMutableArray alloc] init];
    
    NSDictionary *dataDic = [data dictionaryValueForKey:@"data" defaultValue:nil];
    retObject.pn     = [dataDic intValueForKey:@"pn" defaultValue:0];
    retObject.rn     = [dataDic intValueForKey:@"rn" defaultValue:0];
    retObject.total  = [dataDic intValueForKey:@"total" defaultValue:0];
    
    NSArray *dataItems = [dataDic arrayValueForKey:@"list" defaultValue:nil];
    if (nil == dataItems) {
        dataItems = [dataDic arrayValueForKey:@"items" defaultValue:nil];
    }
    for (NSDictionary *dic in dataItems) {
        RCMyOrderItemDataModel *item = [[RCMyOrderItemDataModel alloc] init];
        item.shopName = [dic stringValueForKey:@"shopname" defaultValue:@"" operation:NSStringOperationTypeNone];
            item.status = [dic stringValueForKey:@"status" defaultValue:@"" operation:NSStringOperationTypeNone];
        item.userName = [dic stringValueForKey:@"name" defaultValue:@"" operation:NSStringOperationTypeNone];
        item.mobile = [dic stringValueForKey:@"mobile" defaultValue:@"" operation:NSStringOperationTypeNone];
        item.content = [dic stringValueForKey:@"content" defaultValue:@"" operation:NSStringOperationTypeNone];
        item.shopID = [dic stringValueForKey:@"shopid" defaultValue:@"" operation:NSStringOperationTypeNone];
        item.dateTime = [dic stringValueForKey:@"datetime" defaultValue:@"" operation:NSStringOperationTypeNone];
        [listItems addObject:item];
        [item release];
    }
    retObject.listItems = listItems;
    [listItems release];
    
    // 返回结果数据模型
    return [retObject autorelease];
}
@end
